package com.iyundao.io.Service.Impl;

import com.iyundao.io.Service.PersonalDetailsService;
import com.iyundao.io.mapper.*;
import com.iyundao.io.model.*;
import com.iyundao.io.tools.PartyMemberShow;
import com.iyundao.io.tools.PersonalDetailsShow;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;

@Service
public class PersonalDetailsServiceImpl implements PersonalDetailsService {

    @Autowired
    private UserRoleMapper userRoleMapper;

    @Autowired
    private PartyMemberCustomMapper memberCustomMapper;

    @Autowired
    private IntegralMapper integralMapper;

    @Autowired
    private IntegralRecordMapper integralRecordMapper;

    @Autowired
    private WishSubmitMapper wishSubmitMapper;


    @Override
    public PersonalDetailsShow selectDetails() {

        PersonalDetailsShow sysUser = new PersonalDetailsShow();

        //获取用户基信息，角色，组织
        SysUserProvider sysUser1 = (SysUserProvider) SecurityUtils.getSubject().getPrincipal();
        SysRole sysRole = userRoleMapper.selectBySid(sysUser1.getSid());
        sysUser1.setSysRole(sysRole);

        sysUser.setSysUserProvider(sysUser1);

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        //获取党员信息
        PartyMember partyMember = memberCustomMapper.selectAllByPhone(sysUser1.getPhone());
        PartyMemberShow partyMemberShow = new PartyMemberShow();
        partyMemberShow.setId(partyMember.getId());
        partyMemberShow.setPartymemberaddress(partyMember.getPartymemberaddress());
        partyMemberShow.setPartymemberbirthday(simpleDateFormat.format(partyMember.getPartymemberbirthday()));
        partyMemberShow.setPartymemberjointime(simpleDateFormat.format(partyMember.getPartymemberjointime()));
        partyMemberShow.setPartymembername(partyMember.getPartymembername());
        partyMemberShow.setPartymemberphone(partyMember.getPartymemberphone());
        partyMemberShow.setPartymembersex(partyMember.getPartymembersex());
        sysUser.setPartyMember(partyMemberShow);

        //获取积分总数
        Integral integral = integralMapper.selectByPartyMemberId(partyMember.getId());
        sysUser.setIntegral(integral);


        return sysUser;

    }
}
